package demo19;

/**
 * 目标和
 * https://leetcode.cn/problems/YaVDxD/
 */
class Solution {
    int ret = 0;
    int t;
    public int findTargetSumWays(int[] nums, int target) {
        t = target;
        dfs(nums, 0, 0);
        return ret;
    }

    private void dfs(int[] nums, int index, int sum) {
        if(index == nums.length) {
            if(t == sum) ret++;
        }else {
            dfs(nums, index + 1, sum + nums[index]);
            dfs(nums, index + 1, sum - nums[index]);
        }
    }
}